package com.wnhz.work.yz.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.wnhz.work.yz.R;
import com.wnhz.work.yz.bean.DriverBean;

import org.xutils.x;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by admin on 2016/12/6.
 */
public class DriverPickAdapter extends BaseAdapter {
    private Context context;
    private List<DriverBean.InfoEntity> info1 = new ArrayList<>();
    private View.OnClickListener onClickListener;


    public DriverPickAdapter(Context context, List<DriverBean.InfoEntity> info1, View.OnClickListener onClickListener) {
        this.context = context;
        this.info1 = info1;
        this.onClickListener = onClickListener;
    }

    @Override
    public int getCount() {
        return info1.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        DriverPickViewHolder viewHolder = new DriverPickViewHolder();
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_driver_pick, null);
            viewHolder.tv_name = (TextView) convertView.findViewById(R.id.tv_item_driverName);
            viewHolder.tv_phone = (TextView) convertView.findViewById(R.id.tv_item_driverPhone);
            viewHolder.tv_pick = (TextView) convertView.findViewById(R.id.tv_item_driverPick);
            viewHolder.iv_head = (ImageView) convertView.findViewById(R.id.iv_item_driverPick);

            convertView.setTag(viewHolder);
        } else {
            viewHolder = (DriverPickViewHolder) convertView.getTag();
        }
        x.image().bind(viewHolder.iv_head, info1.get(position).getImg());
        viewHolder.tv_name.setText(info1.get(position).getDriver() + "");
        viewHolder.tv_phone.setText(info1.get(position).getTel() + "");

        viewHolder.tv_pick.setOnClickListener(onClickListener);
        viewHolder.tv_pick.setTag(position);

        return convertView;
    }


    class DriverPickViewHolder {
        TextView tv_name;
        TextView tv_phone;
        TextView tv_pick;
        ImageView iv_head;
    }
}
